package com.handinfo.uimenu.window;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UITools;

/**
 * 处理设置 标签及背包
 * @author venizeng
 * 
 */
public class SetLBHandler extends AbsLBHandler
{
	public static final int NUM_LABEL_DIS = 3;

	protected static final int ID_LABEL_ACTORITEM = 1;
	protected static final int ID_LABEL_SKILL = 2;
	protected static final int ID_LABEL_FUNCTION = 3;

	public SetLBHandler(ILBHandler iHandler)
	{
		super(iHandler);
		m_num_label = NUM_LABEL_DIS;
//		m_labels = new String[] { "道具", "技能", "功能" };
		m_labels =new Image[]{UIManager.IMAGE_LABEL_QUANBU,UIManager.IMAGE_LABEL_QUANBU,UIManager.IMAGE_LABEL_QUANBU} ;
		//
		m_w_label = UITools.W_LABEL_HUGE - 1;
		m_iw_label = 0;
	}

	protected int getLabelIdByLabelIndex(int labelGroupIndex)
	{
		return labelGroupIndex + ID_LABEL_ACTORITEM;
	}

	protected int getLabelIndexByLabelId(int labelId)
	{
		return labelId - ID_LABEL_ACTORITEM;
	}

	/**
	 * 2012-2-17 上午09:40:18 venizeng
	 * @param g
	 */
	public void paintBag(Graphics g)
	{
		switch (m_id_label) {
			case ID_LABEL_ACTORITEM:
				paintActorItem(g);
				break;
			case ID_LABEL_SKILL:
			default:
				paintSkill(g);
				break;
		}
	}

	protected int keyDown()
	{
		switch (m_id_label) {
			case ID_LABEL_ACTORITEM:
				return keyBagDown();
			case ID_LABEL_SKILL:
			default:
				return keySkillDown();
		}
	}

	protected int keyRight()
	{
		switch (m_id_label) {
			case ID_LABEL_ACTORITEM:
				return keyBagRight();
			case ID_LABEL_SKILL:
			default:
				return keySkillRight();
		}
	}

	/**
	 * 技能栏 向下
	 */
	private int keySkillDown()
	{
		int bagDisIndex = getGroupIndex();
		if (bagDisIndex >= (NUM_BAG_DIS - NUM_BAG_COL)) {// 显示最下
			if (m_datas == null) {
				return getDownIndex();
			}
			else {
				if (bagDisIndex + m_index_data_top + NUM_BAG_COL < m_datas.length) {
					setTopDataIndex(m_index_data_top + NUM_BAG_COL);
				}
				else {
					return getDownIndex();
				}
			}
		}
		else {
			bagDisIndex += NUM_BAG_COL;
		}
		return bagDisIndex + INDEX_BAG_FIRST;
	}
	
	
	/**
	 * 技能栏 向右
	 */
	private int keySkillRight()
	{
		int bagDisIndex = getGroupIndex();
		if (m_index_data_top + bagDisIndex + 1 >= NUM_BAG_DIS) {
			return getRightIndex();
		}
		else {
			if (bagDisIndex == NUM_BAG_DIS - 1) {// 显示最下
//				m_index_data_top += 1;
				setTopDataIndex(m_index_data_top + NUM_BAG_COL);
			}
			else {
				bagDisIndex++;
			}
		}
		return bagDisIndex + INDEX_BAG_FIRST;
	}
}
